package com.An.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @auther AnYang
 * @date 2022/3/23 22:58
 **/
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		/*添加视图控制*/
		registry.addViewController("/adminLogin.html").setViewName("admin/login");
		registry.addViewController("/studentLogin.html").setViewName("student/login");
		registry.addViewController("/").setViewName("index");
		registry.addViewController("/index.html").setViewName("index");
		registry.addViewController("/main.html").setViewName("admin/dashboard");
		registry.addViewController("/homePage.html").setViewName("student/dashboard");

	}

	//自定义国际化组件
	@Bean
	public LocaleResolver localeResolver() {
		return new MyLocaleResolve();
	}

	//注册到SpringBoot,添加拦截器
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		//拦截部分信息，放过静态资源目录下的css，js，img
		registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/adminLogin.html", "/", "/user/admin", "/static/**", "/studentLogin.html", "/user/student", "/homePage.html", "/index.html");
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
	}
}